package cd.cdyb.sms.dao;

import cd.cdyb.sms.domain.Company;
import cd.cdyb.sms.dto.expand.ExCompanyDto;
import cd.cdyb.sms.dto.query.CompanyQueryDto;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author lin
 * @since 2024-05-14
 */
@Mapper
public interface CompanyDao extends BaseMapper<Company> {


    /**
     * 查询公司分页
     *
     * @param companyQueryDto 查询条件
     * @param page 分页条件
     * @return 查询结果
     */
    @Select(" <script> "
            + " select * from company "
            + " <where> "
            + " <if test = \" companyQueryDto.companyName != null and  companyQueryDto.companyName neq '' \"> and company_name like concat('%', #{companyQueryDto.companyName},'%') </if>"
            + " <if test = \" companyQueryDto.phone != null and  companyQueryDto.phone neq '' \"> and phone = #{companyQueryDto.phone} </if>"
            + " </where>"
            + " </script>")
    IPage<ExCompanyDto> findCompanyPage(@Param("companyQueryDto") CompanyQueryDto companyQueryDto, @Param("page") Page<Company> page);

    /**
     * 通过身份key查询公司信息
     *
     * @param companyKey 身份key
     * @return 公司信息
     */
    @Select("select * from company where company_key = #{companyKey} and is_deleted = false")
    Company getCompanyByCompanyKey(@Param("companyKey") String companyKey);





}
